
#include "timer.h"

#pragma comment(lib, "winmm.lib")

unsigned long Timer::m_freq = 0;
float Timer::m_freq_f = 0.0f;

Timer::Timer()
{
	LARGE_INTEGER temp;
	if (!m_freq)
	{
		::QueryPerformanceFrequency(&temp);
		m_freq = (unsigned long)(temp.QuadPart / 1000);
		m_freq_f = (float)temp.QuadPart;
	}
	reset();
}

void Timer::reset()
{
	::QueryPerformanceCounter(&m_start_count);
}

unsigned long Timer::get_elapse_milliseconds() const
{
	LARGE_INTEGER now_count;
	::QueryPerformanceCounter(&now_count);
	return (unsigned long)((now_count.QuadPart - m_start_count.QuadPart + (m_freq >> 1)) / m_freq);
}

float Timer::get_elapse_seconds() const
{
	LARGE_INTEGER now_count;
	::QueryPerformanceCounter(&now_count);
	return (float)(now_count.QuadPart - m_start_count.QuadPart) / m_freq_f;
}
